package thesis.filesharing.web.auth;

import java.util.Collection;
import java.util.HashSet;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;

public class AuthenticationUserDetails implements UserDetails {
	
	private static final long serialVersionUID = -4501807732974556993L;
	
	private String username;
	private String password;
	private HashSet<GrantedAuthority> authorities = new HashSet<GrantedAuthority>();
	private boolean isActive;
	
	public AuthenticationUserDetails(User user) {
		this.username = user.getUsername();
		this.password = user.getPassword();
		this.authorities.addAll(user.getAuthorities());
		this.isActive = user.isEnabled();
	}
	
	@Override
	public Collection<GrantedAuthority> getAuthorities() {
		return this.authorities;
	}

	@Override
	public String getPassword() {
		return this.password;
	}

	@Override
	public String getUsername() {
		return this.username;
	}

	@Override
	public boolean isAccountNonExpired() {
		return true;
	}

	@Override
	public boolean isAccountNonLocked() {
		return true;
	}

	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

	@Override
	public boolean isEnabled() {
		return this.isActive;
	}
}
